<?php

##################################################
#
# Copyright (c) 2004-2008 OIC Group, Inc.
# Written and Designed by Adam Kessler
#
# This file is part of Exponent
#
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################

/*
    Change logs
    Jan 29, 2011 - trungdt - Implement support OpenID
    Mar 6, 2011 - trungdt - Support time-belt
*/
class user {
    function form($object) {
        if (!defined('SYS_FORMS')) include_once(BASE.'subsystems/forms.php');
        exponent_forms_initialize();
        
        $i18n = exponent_lang_loadFile('datatypes/user.php');
        
        $form = new form();
        if (!isset($object->id)) {
            // If the user object has no id, then this is a new user form.
            // Populate the empty user object with default attributes,
            // so that the calls to $form->register can confidently dereference
            // thes attributes.
            $object->firstname = '';
            $object->lastname = '';
            $object->email = '';
            $object->username="";
            $object->time_belt=7;
            // Username and Password can only be specified for a new user.  To change the password,
            // a different form is used (part of the loginmodule)
            //$form->register(null,"",new htmlcontrol('<img align=right src="'.THEME_RELATIVE.'images/face.gif" border=0>'));
            //$form->register('username',$i18n['desired_username'],new textcontrol());
            
            $form->register('username',$i18n['desired_username'],new usernamecontrol($object->username,true,55));
           
        $form->register('pass1',$i18n['pass1'], new passwordcontrol("",55,false,35));
        $form->register('pass2',$i18n['pass2'],new passwordcontrol("",55,false,35,"pass1"));
            // Jan 29, 2011 - trungdt - comment this code
            //$form->register(null,'',new htmlcontrol('<br />'));
        } else {
            $form->meta("id",$object->id);
            //Jan 25, 2013 - sonhb - Edit password in admincp
        $form->register('pass1',$i18n['pass1'], new passwordcontrol("",55,false,35,'','',false));
        $form->register('pass2',$i18n['pass2'],new passwordcontrol("",55,false,35,"pass1",'',false));
        }
        
        // Jan 29, 2011 - trungdt - change to support openID - begin
        $temp=aboid_getSession();
        $defaultemail="";
        $default_firstname=""; $default_lastname="";
        $default_email_disable_field=false;
        if ($temp)
        {
            $defaultemail=$temp->email;        
            $default_firstname=$temp->first_name;
            $default_lastname=$temp->last_name;
            $default_email_disable_field=true;
        }
        else
        {
            $defaultemail=$object->email;        
            $default_firstname=$object->firstname;
            $default_lastname=$object->lastname;
            $default_email_disable_field=false;
        }
        
        // Mar 6, 2011 - trungdt - add time belt
        $time_belt=array();
        $time_belt[-120]="(GMT -12:00) Eniwetok, Kwajalein";
        $time_belt[-110]="(GMT -11:00) Midway Island, Samoa";
        $time_belt[-100]="(GMT -10:00) Hawaii";
        $time_belt[-90]="(GMT -9:00) Alaska";
        $time_belt[-80]="(GMT -8:00) Pacific Time (US &amp; Canada)";
        $time_belt[-70]="(GMT -7:00) Mountain Time (US &amp; Canada)";
        $time_belt[-60]="(GMT -6:00) Central Time (US &amp; Canada), Mexico City";
        $time_belt[-50]="(GMT -5:00) Eastern Time (US &amp; Canada), Bogota, Lima";
        $time_belt[-45]="(GMT -4:30) Caracas";
        $time_belt[-40]="(GMT -4:00) Atlantic Time (Canada), La Paz, Santiago";
        $time_belt[-35]="(GMT -3:30) Newfoundland";
        $time_belt[-30]="(GMT -3:00) Brazil, Buenos Aires, Georgetown";
        $time_belt[-20]="(GMT -2:00) Mid-Atlantic";
        $time_belt[-10]="(GMT -1:00 hour) Azores, Cape Verde Islands";
        $time_belt[0]="(GMT) Western Europe Time, London, Lisbon, Casablanca";
        $time_belt[10]="(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris";
        $time_belt[20]="(GMT +2:00) Kaliningrad, South Africa, Cairo";
        $time_belt[30]="(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg";
        $time_belt[35]="(GMT +3:30) Tehran";
        $time_belt[40]="(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi";
        $time_belt[45]="(GMT +4:30) Kabul";
        $time_belt[50]="(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent";
        $time_belt[55]="(GMT +5:30) Mumbai, Kolkata, Chennai, New Delhi";
        $time_belt[60]="(GMT +6:00) Almaty, Dhaka, Colombo";
        $time_belt[65]="(GMT +6:30) Yangon, Cocos Islands";
        $time_belt[70]="(GMT +7:00) Bangkok, Hanoi, Jakarta";
        $time_belt[80]="(GMT +8:00) Beijing, Perth, Singapore, Hong Kong";
        $time_belt[90]="(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk";
        $time_belt[95]="(GMT +9:30) Adelaide, Darwin";
        $time_belt[100]="(GMT +10:00) Eastern Australia, Guam, Vladivostok";
        $time_belt[110]="(GMT +11:00) Magadan, Solomon Islands, New Caledonia";
        $time_belt[120]="(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka";
        $object->time_belt=$object->time_belt*10;
        // Mar 6, 2011 - trungdt - add time belt - end
        
        // Register the basic user profile controls.
        
        $html=' 
        <div id="nameControl" class="control required">
        <label>
        <span class="label">'.$i18n['firstname'].'</span>
        <input class="text required" type="text" name="firstname"  value="'.$default_firstname.'" size="55" maxlength="50">
        </label>        
        </div>
        
        <div id="nameControl" class="control required">
        <label>
        <span class="label">'.$i18n['lastname'].'</span>
        <input class="text required" type="text" name="lastname" value="'.$default_lastname.'" size="55" maxlength="50">
        </label>        
        </div>';
        $form->register(null,"",new htmlcontrol($html));
       
        //$form->register('firstname',$i18n['firstname'],new textcontrol($default_firstname,60,false,200,"",true));
        //$form->register('lastname',$i18n['lastname'],new textcontrol($default_lastname,60,false,200,"",true));
        //$form->register(null,'',new htmlcontrol('<br />'));
        // set default email if this user is logged in by OpenID
        $form->register('email',$i18n['email'],new textcontrol($defaultemail,55 , $default_email_disable_field,50,"","email"));
        $form->register('time_belt',$i18n['timezone'],new dropdowncontrol($object->time_belt,$time_belt));
        
        
        //else
        //    $form->register("fakefield","Đăng ký cầu nguyện",new prayonline_userform());
        // Jan 29, 2011 - trungdt - change to support openID - end
        $form->register('submit','',new buttongroupcontrol($i18n['save'],'',$i18n['cancel']));
        
        return $form;
    }
    
    function update($values,$object) {
        $object->firstname = strip_tags($values['firstname']);
        $object->lastname = strip_tags($values['lastname']);
        if(isset($values['pass1'])&&$values['pass1']!='')
        $object->password = md5($values['pass1']);
        $object->email = strip_tags($values['email']);
        $object->time_belt = floatval($values['time_belt'])/(float)10;
        return $object;
    }
}

?>
